<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script src="./lib/axios.js"></script>
    <script>
      function delay() {
        return new Promise((resolve, reject) => {
          setTimeout(() => {
            resolve("成功了");
          }, 2000);
        });
      }

      // delay().then((res) => {
      //   console.log(res);
      // });

      async function asyncFun() {
        // await 后面等待的是一个 Promise 对象
        const res = await delay();
        console.log(res);
        const res1 = await delay();
        console.log(res1);
        const res2 = await delay();
        console.log(res2);
      }

      // asyncFun();

      async function chatRobot() {
        const res1 = await axios({
          url: "http://ajax-api.itheima.net/api/robot",
          params: { spoken: "你吃了吗" },
        });
        console.log(res1.data.data.info.text);
        const res2 = await axios({
          url: "http://ajax-api.itheima.net/api/robot",
          params: { spoken: "你今年多大了" },
        });
        console.log(res2.data.data.info.text);
        const res3 = await axios({
          url: "http://ajax-api.itheima.net/api/robot",
          params: { spoken: "你多高" },
        });
        console.log(res3.data.data.info.text);
      }

      chatRobot();
    </script>
  </body>
</html>
